package magis;

import edu.byu.intex2.data.bo.PhysicalCar;
import edu.byu.intex2.data.bo.Warranty;
import javax.swing.table.*;

/**
 * Warranty JTable Table Model
 * Displays Miles, Months, and Type
 * @author Brady White
 */
public class WarrantyTableDataModel extends AbstractTableModel {

    PhysicalCar pc = null;

    public WarrantyTableDataModel(PhysicalCar pc) {
        this.pc = pc;
    }

    public int getRowCount() {
        return pc.getWarranties().size();
    }

    public int getColumnCount() {
        return 3;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        // Go through columnIndex and assign respective attributes to the columns
        Warranty warranty = pc.getWarranties().get(rowIndex);

        try { 
            switch (columnIndex) {
                case 0:
                    return warranty.getMiles();
                case 1:
                    return warranty.getMonths();
                case 2:
                    return warranty.getType();
                default:
                    return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /** Allow user to edit cells but first column  */
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    /** @return saleLine from rowIndex */
    public Warranty getWarranty(int rowIndex){
        return pc.getWarranties().get(rowIndex);
    }
}
